package karaoke.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import karaoke.excepcion.DAOExcepcion;
import karaoke.modelo.Evento;
import karaoke.negocio.GestionEvento;

/**
 * Servlet implementation class LocalModificarServlet
 */
@WebServlet("/EventoModificarServlet")
public class EventoModificarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EventoModificarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
		
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int idEvento = Integer.parseInt(request.getParameter("txtIdEvento"));
		String nombre = request.getParameter("txtNombre");
		String fecha = request.getParameter("txtFecha");
		String hora = request.getParameter("txtHora");
		int aforo = Integer.parseInt(request.getParameter("txtAforo"));
		String descripcion = request.getParameter("txtDescripcion");
//		int idReserva = Integer.parseInt(request.getParameter("txtIdReserva"));
	
		Evento evento = new Evento();
		evento.setIdEvento(idEvento);
		evento.setNombre_Evento(nombre);
		evento.setFecha_Evento(fecha);
		evento.setHora_Evento(hora);
		evento.setAforo_Evento(aforo);
		evento.setDescripcion_Evento(descripcion);
		evento.setReserva_idReserva(1);
		
		GestionEvento negocio = new GestionEvento();
		try {
			negocio.actualizar(evento);
			response.sendRedirect(request.getContextPath()	+ "/EventoBuscarServlet");
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}